;; generic/as.scm - (c) rohan drape, 2003-2005

;; Coerce types.

(define-generic as-list)
(define-method (as-list (l <List>))   l)
(define-method (as-list (s <String>)) (string->list s))
(define-method (as-list (v <Vector>)) (vector->list v))
(define-method (as-list (s <Stream>)) (stream->list s))

(define-generic as-vector)
(define-method (as-vector (v <Vector>)) v)
(define-method (as-vector (s <String>)) (string->vector s))
(define-method (as-vector (l <List>))   (list->vector l))
(define-method (as-vector (s <Stream>)) (stream->vector s))

(define-generic as-string)
(define-method (as-string (s <String>)) s)
(define-method (as-string (c <Char>))   (make-string 1 c))
(define-method (as-string (s <Symbol>)) (symbol->string s))
(define-method (as-string (n <Num>))    (number->string n))
(define-method (as-string (l <List>))   (list->string l))

(define-generic as-stream)
(define-method (as-stream (v <Any>))    (value->stream v))
(define-method (as-stream (s <Stream>)) s)
(define-method (as-stream (l <List>))   (list->stream l))

(define-generic as-symbol)
(define-method (as-symbol (s <Symbol>)) s)
(define-method (as-symbol (s <String>)) (string->symbol s))

(define-generic as-warp)
(define-method (as-warp (s <Symbol>)) (symbol->warp s))
(define-method (as-warp (n <Num>))    (number->warp n))

#|
(define-method (as-pt (x <Num>) (y <Num>)) (make-pt x y))
(define-method (as-pt (v <Vector>))        (vector->pt v))
(define-method (as-pt (l <List>))          (ptL->pt l))
|#
